package o;

import com.huawei.appgallery.splashscreen.impl.cache.ImageCacheBean;
import java.security.SecureRandom;
import java.util.ArrayList;

public class cyz {
    public static int ˎ(int i) {
        int i2;
        int i3 = 0;
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        int i4 = 0;
        for (i2 = 0; i2 < i; i2++) {
            cyv ॱ = cyx.ॱ(i2);
            if (ॱ == null) {
                cyq.ˋ.ˏ("RandomSelectionManager", "imageCache == null");
            } else {
                ImageCacheBean ॱ2 = ॱ.ॱ();
                if (ॱ2.ʻ() == -1 && ॱ2.ˊॱ() > 0 && cyw.ॱ().ˏ(ॱ2) != null) {
                    i4 += ॱ2.ˊॱ();
                    arrayList.add(Integer.valueOf(i2));
                    arrayList2.add(Integer.valueOf(i4));
                    cyq.ˋ.ˋ("RandomSelectionManager", "index=" + i2 + "; rate=" + ॱ2.ˊॱ());
                }
            }
        }
        if (i4 <= 0) {
            return -1;
        }
        i2 = new SecureRandom().nextInt(i4);
        while (i3 < arrayList2.size()) {
            if (i2 < ((Integer) arrayList2.get(i3)).intValue()) {
                i4 = ((Integer) arrayList.get(i3)).intValue();
                break;
            }
            i3++;
        }
        i4 = -1;
        cyq.ˋ.ˋ("RandomSelectionManager", "randomRate=" + i2 + "; randomIndex=" + i4);
        return i4;
    }
}
